
<template>
    <view class="viewport">
        <view class="logo">
            <image class="LOGO" src="../../static/img-xcx/logo.jpg"></image>
        </view>
        <view class="login">
            <button class="button phone"  @click="oneClickLogin" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">
                <text class="icon icon-phone" ></text>
                一键登录
            </button>
			<!-- <view class="top" >
				<button class="button phone" @click="enroll">
							 <uni-icons type="paperplane" size="30" color="115, 201, 145"  ></uni-icons>
							    <text >账号登录</text>
				</button>
			</view>
			<text class="cash" @click="aa" link >没有账号,去注册!</text> -->
            <view class="tips">
                <view class="circle">
				<checkbox-group >
					
					<label >
						<checkbox value="cb" />
					</label>
				</checkbox-group>
			</view>
				<text>请先同意 <text @click="serve" class="aa">《服务协议》</text > 和<text class="aa" @click="privacy">《用户协议》</text> </text>
				</view>
        </view>
    </view>
</template>
<script setup>
import userApi from '@/api/user'
import {  ref } from "vue";
import { useUserStore } from '@/stores/user'
const formList=ref({
  wxCode:"",
  invitationCode:""
})
// 获取手机号code
const code=ref("")
// 调用存储
const userStore = useUserStore()
async function oneClickLogin() {
  try {
    // 调用 wx.login 方法获取用户的 code
    const res = await wx.login();
    console.log(res);
    formList.value.wxCode = res.code
    // 如果成功获取到了用户的 code
    const result = await userApi.getOpenId(formList.value);
userStore.token = result.data.token
    console.log(result);
    userStore.token = result.data.token
  } catch (error) {
    console.log(error);
  }
}
// console.log("getCurrentPages",currentPage.route);
  async function getPhoneNumber(e){
    code.value = e.detail.code.toString();
const res=  await userApi.getWXToken(code.value)
console.log(res);
if (res.code===200) {
      return  uni.switchTab({
      url: '/pages/personal/index',
    })
    }else{
        uni.showToast({
     title:"请先登录",
     icon: 'closeempty',
     duration: 2000//持续的时间
   })
    }    
userStore.token = res.data.token
}
function serve(){
    uni.navigateTo({ url: '/subpkg_user/serve/serve' })
}
function privacy(){
    uni.navigateTo({ url: '/subpkg_user/privacy/privacy' })
}
</script>
<style lang="scss" scoped>
page {
    height: 100%;
}
.viewport {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 20rpx 40rpx;
}
.logo {
    flex: 1;
    text-align: center;
    image {
        width: 220rpx;
        height: 220rpx;
        margin-top: 100rpx;
    }
}
.LOGO {
    border-radius: 50%;
}
.login {
    display: flex;
    flex-direction: column;
    height: 600rpx;
    padding: 40rpx 20rpx 20rpx;
    .button {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 100%;
        height: 80rpx;
        font-size: 28rpx;
        border-radius: 72rpx;
        color: #fff;
        .icon {
            font-size: 40rpx;
            margin-right: 6rpx;
        }
    }
    .phone {
        background-color: #28bb9c;
    }
    .wechat {
        background-color: #06c05f;
    }
    .tips {
		margin-top: 20px;
		height: 30px;
        bottom: 80rpx;
        left: 20rpx;
        right: 20rpx;
        font-size: 22rpx;
        // color: #999;
        text-align: center;
		align-items: center;
		display: flex;
    }
}
.register{
    text-align: center;
    margin-top: 20px;
    width: 85vw;
    height: 80rpx;
    font-size: 28rpx;
    display: flex;
    border-radius: 72rpx;
    align-items: center;
    justify-content: center;
    color: #fff;
    background-color: #28bb9c;
}
	
.top{
	padding-top: 20px;
}
.cash{
	width: 90%;
	height: 20px;
	margin-top: 10px;
	margin-left: 62%;
	color: #28bb9c;
}
.circle{
    margin-left: 15%;
   
}
.aa{
    font-size: 13px;
    color: #06c05f;
}
</style>